<?php

class Sponsors extends HTech_Db_Table
{
    protected $_name    = 'view_sponsors';
    protected $_primary = 'SponsorId';  
    
    protected $_referenceMap    = array(
        'Partners' => array(
            'columns'           => array('PartnerId'),
            'refTableClass'     => 'Partners',
            'refColumns'        => array('PartnerId')
        )
    );
            
    protected function _setGridMetadata()
    {
        $this->_gridMetadata['title'] = $this->translate("Sponsors");
        $this->_gridMetadata['onClick'] = 'sponsor.sponsor.view';
        $this->_gridMetadata['params'] = array('PartnerId');
        $this->_gridMetadata['headers'] = array
            (
                array('SponsorId',  80, $this->translate("Id"),         'String'),
                array('Status',    100, $this->translate("Status"),     'String'),
                array('WomenOnly', 100, $this->translate("Women only"), 'String'),
                array('Username',  100, $this->translate("Username"),   'String'),
                array('Sponsor',   300, $this->translate("Sponsor"),    'String'),
                array('FullName',  200, $this->translate("Contact"),    'String'),
                array('Email',     200, $this->translate("Email"),      'String'),
                array('Partner',   250, $this->translate("Partner"),    'String'),
                array('Comments',  550, $this->translate("Comments"),   'String')
            );
        return $this;
    }
    
    protected function _setRecordPerformance() 
    {
        $this->_record->p = $this->getPerformance($this->_record->d, new Zend_Date());
    }

    public function getPerformance(Zend_Db_Table_Row $row, Zend_Date $date, $options = array())
    {
        $row = $row; $date = $date; $options = $options;
        $color = array('red','orange','yellow','green');        
        $c = (object) array(
            'score'            => $color[rand(0,3)],
            'active_loans'     => $color[rand(0,3)],
            'delinquent_loans' => $color[rand(0,3)],
            'due_amount'       => $color[rand(0,3)],
            'clients'          => $color[rand(0,3)],
            'women_pct'        => $color[rand(0,3)],
            'balance'          => $color[rand(0,3)],
            'par15'            => $color[rand(0,3)],
            'w_off_pct'        => $color[rand(0,3)],
            'op_income'        => $color[rand(0,3)],
            'disbursed_loans'  => $color[rand(0,3)],
            'disbursed_amount' => $color[rand(0,3)],
            'w_off'            => $color[rand(0,3)],
            'kp_income'        => $color[rand(0,3)]
        );
        $performance = (object) array(        
            'score'            => round(rand(0,100),2),
            'active_loans '    => round(rand(100,400),0),
            'delinquent_loans' => round(rand(10,70),0),
            'due_amount'       => round(rand(10000,100000),2),
            'clients'          => round(rand(100,400),0),
            'women_pct'        => round(rand(70,100),2),
            'balance'          => round(rand(100000,1000000),2),
            'par15'            => round(rand(1,10),2),
            'w_off_pct'        => round(rand(0,10),2),
            'op_income'        => round(rand(10000,100000),2),
            'disbursed_loans'  => round(rand(10,200),0),
            'disbursed_amount' => round(rand(100000,200000),2),
            'w_off'            => round(rand(1000,20000),2),
            'kp_income'        => round(rand(50000,500000),2),
            'c' => $c
        );
        return $performance;
    }
}
